import 'package:flutter/material.dart';

main() => runApp(MyApp());

// 生成代码快捷键  stl
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: GLHomePage(),
    );
  }
}

class GLHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("基础的widget"),
        ),
        body: GLHomeContent());
  }
}

class GLHomeContent extends StatefulWidget {
  const GLHomeContent({super.key});

  @override
  State<GLHomeContent> createState() => _GLHomeContentState();
}

class _GLHomeContentState extends State<GLHomeContent> {
  final usenameTextEditController = TextEditingController();
  final passwordTextEditController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Theme(
        data: ThemeData(primaryColor: Colors.red),
        child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              children: [
                TextField(
                  controller: usenameTextEditController,
                  decoration: InputDecoration(
                    // labelText: "用户名",
                    icon: Icon(Icons.people),
                    hintText: "请输入用户名",
                    border: OutlineInputBorder(),
                    // border: InputBorder.none,  // 去除边框
                    filled: true,
                    fillColor: Colors.blue[100], // 输入框背景颜色
                  ),
                  onChanged: (value) {
                    print("监听输入框输入:$value");
                  },
                  onSubmitted: (value) {
                    print("onSubmitted:$value");
                  },
                ),
                SizedBox(height: 10),
                TextField(
                  controller: passwordTextEditController,
                  decoration: InputDecoration(
                    labelText: "密码",
                    icon: Icon(Icons.lock),
                    border: OutlineInputBorder(),
                  ),
                ),
                SizedBox(height: 10),
                Container(
                  // 在Container填充宽度高度
                  width: double.infinity,
                  height: 50,
                  child: ElevatedButton(
                    // button 1
                    child: Text(
                      '登录', // 设置按钮文本
                      style: TextStyle(
                        fontSize: 20, // 字体大小设置为20，你可以根据需要调整
                      ),
                    ),
                    onPressed: () {
                      // 1、获取用户名和密码
                      final username = usenameTextEditController.text;
                      final password = passwordTextEditController.text;

                      // usenameTextEditController.text = "";
                      // passwordTextEditController.text = "";
                      print("账号：$username,密码：$password");
                    },
                    style: ButtonStyle(
                      backgroundColor: MaterialStateProperty.resolveWith<Color>(
                        (Set<MaterialState> states) {
                          if (states.contains(MaterialState.pressed)) {
                            return Colors.blue.withOpacity(0.7); // 按下时的颜色
                          }
                          return Colors.blue; // 默认颜色
                        },
                      ),
                    ),
                  ),
                )
              ],
            )));
  }
}
